var Tool = require("tool.js");
var Login = require("privacy_login.js");
var Log = require("core_log.js");
var RequestHttps = require("request_https.js");

/**
 * 微信登录
 *  文档：https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
 */
function gainPhone(_e, _hostname, _port, _path, _success){ 
  var logCallerName = gainPhone.name;
  if (_e.detail.errMsg == "getPhoneNumber:ok") {
    RequestHttps
      .postRequest(_hostname, _port, _path, {
        encryptedData: _e.detail.encryptedData,
        iv: _e.detail.iv
      })
      .then(function (res) {
        _success(res);
      });
  }else{
    Log.error(logCallerName, '获取手机号失败', _e.detail.errMsg);
    Tool.showInfo('获取手机号失败:' + _e.detail.errMsg);
  }
}

/**
 * 暴露接口
 */
module.exports = {
  gainPhone
};